 function [svcv,sstd,scor]=ss_var(GG,RR,SDX)
% ==================================================
%SSVAR
%function [svcv,sstd,scor]=ss_var(GG,RR,SDX)
%Solve Lyapunov Equation of a state space system 
%where transition equation is 
% s(t)=GG*s(t-1)+R*n(t)   V( n(t) ) = SDX'*SDX 
% Obtain 
% SVCV  State variance covariance 
% SSTD  State standard deviations 
% SCOR  State correlation matrix (at lag 0) 
% Alejandro Justiniano Jan 17 2008 
% ===================================================
if size(RR,1)~=size(GG,1); error('GG and RR mistmatch');end 
if size(RR,2)~=size(SDX,1);error('SDX and RR mistmatch');end 
svcv=disclyap_fast(GG,RR*(SDX')*(SDX)*(RR')); 
check=lyapunov_symm(GG,RR*(SDX')*(SDX)*(RR')); 
if max(max(abs(svcv-check))) > 1e-3 
    warning('Disclyap_fast and Lyapunov Symm give different answers'); 
end 
sstd=sqrt(diag(svcv)); 
scor =svcv./(sstd*sstd'); 
if max(abs(diag(scor)-ones(size(scor,1),1))) > 1e-10 
    error('Correlations wrongly computed') 
end 
    

